/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/{{apis}}/rest/Abstract{{apiEntities}}Resource.java.hbs
 */
package cn.ibizlab.api.rest;

import java.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import cn.ibizlab.util.domain.ImportResult;
import cn.ibizlab.api.dto.*;
import cn.ibizlab.api.mapping.*;
import cn.ibizlab.core.authentication.domain.AuthLogin;
import cn.ibizlab.core.authentication.service.AuthLoginService;
import cn.ibizlab.core.authentication.filter.AuthLoginSearchContext;

/**
 * 实体[Auth] rest实现
 *
 * @author generator
 */
@Slf4j
public abstract class AbstractAuthResource {

    @Autowired
    public AuthLoginService authLoginService;

    @Autowired
    @Lazy
    public AuthLoginCommonDTOMapping authLoginCommonDtoMapping;

    @Autowired
    @Lazy
    public AuthLoginDTOMapping authLoginDtoMapping;

    @Autowired
    @Lazy
    public AuthLoginFilterDTOMapping authLoginFilterDtoMapping;

    @Autowired
    @Lazy
    public AuthLoginRequestDTOMapping authLoginRequestDtoMapping;

    @Autowired
    @Lazy
    public AuthLoginResponseDTOMapping authLoginResponseDtoMapping;

    @Autowired
    @Lazy
    public AuthLogincaptchaDTOMapping authLogincaptchaDtoMapping;

    @Autowired
    @Lazy
    public AuthLoginchangePwdDTOMapping authLoginchangePwdDtoMapping;


    /**
    * Bind 认证接口
    * 将社交平台用户与uaa用户进行绑定
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "Bind", tags = {"认证接口" },  notes = "Auth-Bind 将社交平台用户与uaa用户进行绑定")
    @PostMapping("auths/bind")
    public ResponseEntity<AuthLoginResponseDTO> bind
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.bind(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * Cache_evict 认证接口
    * 
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginDTO>
    */
    @ApiOperation(value = "Cache_evict", tags = {"认证接口" },  notes = "Auth-Cache_evict ")
    @PostMapping("auths/cache_evict")
    public ResponseEntity<AuthLoginDTO> cacheEvict
            (@Validated @RequestBody AuthLoginDTO dto) {
        AuthLogin domain = authLoginDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.cacheEvict(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginDtoMapping.toDto(rt));
    }

    /**
    * Captcha 认证接口
    * 
    *
    * @param dto dto
    * @return ResponseEntity<AuthLogincaptchaDTO>
    */
    @ApiOperation(value = "Captcha", tags = {"认证接口" },  notes = "Auth-Captcha ")
    @PostMapping("auths/captcha")
    public ResponseEntity<AuthLogincaptchaDTO> captcha
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.captcha(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLogincaptchaDtoMapping.toDto(rt));
    }

    /**
    * Login 认证接口
    * 
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "Login", tags = {"认证接口" },  notes = "Auth-Login ")
    @PostMapping("auths/login")
    public ResponseEntity<AuthLoginResponseDTO> login
            (@Validated @RequestBody AuthLoginRequestDTO dto) {
        AuthLogin domain = authLoginRequestDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.login(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * LoginByCode 认证接口
    * 
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "LoginByCode", tags = {"认证接口" },  notes = "Auth-LoginByCode ")
    @PostMapping("auths/loginbycode")
    public ResponseEntity<AuthLoginResponseDTO> loginByCode
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.loginByCode(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * LoginBySmsCode 认证接口
    * 用户通过手机获取短信验证码进行登录
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "LoginBySmsCode", tags = {"认证接口" },  notes = "Auth-LoginBySmsCode 用户通过手机获取短信验证码进行登录")
    @PostMapping("auths/loginbysmscode")
    public ResponseEntity<AuthLoginResponseDTO> loginBySmsCode
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.loginBySmsCode(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * Logout 认证接口
    * 
    *
    * @param id id
    * @return ResponseEntity<AuthLoginDTO>
    */
    @ApiOperation(value = "Logout", tags = {"认证接口" },  notes = "Auth-Logout ")
    @GetMapping("auths/{id}/logout")
    public ResponseEntity<AuthLoginDTO> logoutById
            (@PathVariable("id") String id) {
        AuthLogin rt = authLoginService.logout(id);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginDtoMapping.toDto(rt));
    }

    /**
    * Rebind 认证接口
    * 提供登录用户换绑手机能力，换绑前需要发送短信验证码验证手机
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginDTO>
    */
    @ApiOperation(value = "Rebind", tags = {"认证接口" },  notes = "Auth-Rebind 提供登录用户换绑手机能力，换绑前需要发送短信验证码验证手机")
    @PostMapping("auths/rebind")
    public ResponseEntity<AuthLoginDTO> rebind
            (@Validated @RequestBody AuthLoginDTO dto) {
        AuthLogin domain = authLoginDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.rebind(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginDtoMapping.toDto(rt));
    }

    /**
    * Refresh_token 认证接口
    * 
    *
    * @param id id
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "Refresh_token", tags = {"认证接口" },  notes = "Auth-Refresh_token ")
    @GetMapping("auths/{id}/refresh_token")
    public ResponseEntity<AuthLoginResponseDTO> refreshTokenById
            (@PathVariable("id") String id) {
        AuthLogin rt = authLoginService.refreshToken(id);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * Register 认证接口
    * 通过手机短信认证注册系统用户
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "Register", tags = {"认证接口" },  notes = "Auth-Register 通过手机短信认证注册系统用户")
    @PostMapping("auths/register")
    public ResponseEntity<AuthLoginResponseDTO> register
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.register(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * SendSMSCode 认证接口
    * 调用短信平台服务发送验证码
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "SendSMSCode", tags = {"认证接口" },  notes = "Auth-SendSMSCode 调用短信平台服务发送验证码")
    @PostMapping("auths/sendsmscode")
    public ResponseEntity<AuthLoginResponseDTO> sendSmsCode
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.sendSmsCode(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * SocialRegister 认证接口
    * 通过社交平台认证自动注册系统用户
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "SocialRegister", tags = {"认证接口" },  notes = "Auth-SocialRegister 通过社交平台认证自动注册系统用户")
    @PostMapping("auths/socialregister")
    public ResponseEntity<AuthLoginResponseDTO> socialRegister
            (@Validated @RequestBody AuthLoginCommonDTO dto) {
        AuthLogin domain = authLoginCommonDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.socialRegister(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }

    /**
    * Unlock 认证接口
    * 
    *
    * @param id id
    * @return ResponseEntity<AuthLoginDTO>
    */
    @ApiOperation(value = "Unlock", tags = {"认证接口" },  notes = "Auth-Unlock ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-AuthLogin-Unlock-all','uaa-AuthLogin-Get-all')")
    @GetMapping("auths/{id}/unlock")
    public ResponseEntity<AuthLoginDTO> unlockById
            (@PathVariable("id") String id) {
        AuthLogin rt = authLoginService.unlock(id);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginDtoMapping.toDto(rt));
    }

    /**
    * change_pwd 认证接口
    * 
    *
    * @param dto dto
    * @return ResponseEntity<AuthLoginResponseDTO>
    */
    @ApiOperation(value = "change_pwd", tags = {"认证接口" },  notes = "Auth-change_pwd ")
    @PostMapping("auths/change_pwd")
    public ResponseEntity<AuthLoginResponseDTO> changePwd
            (@Validated @RequestBody AuthLoginchangePwdDTO dto) {
        AuthLogin domain = authLoginchangePwdDtoMapping.toDomain(dto);
        AuthLogin rt = authLoginService.changePwd(domain);
        return ResponseEntity.status(HttpStatus.OK).body(authLoginResponseDtoMapping.toDto(rt));
    }


}
